﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace OP20.ViewModels
{
    public class ST14CyManagerViewModel : BindableBase
    {
        private readonly IRegionManager _regionManager;

        public ST14CyManagerViewModel(IRegionManager regionManager)
        {
            _regionManager = regionManager;

            InitParam();
        }

        private void InitParam()
        {

            CylinderDelay.DelayTime01 = ST14CarryUpDown01Cy.cylinderPCToPLC_Global.tBackTime;
            CylinderDelay.DelayTime02 = ST14CarryUpDown02Cy.cylinderPCToPLC_Global.tBackTime;
            CylinderDelay.DelayTime03 = ST14ChuoWei01Cy.cylinderPCToPLC_Global.tBackTime;
            CylinderDelay.DelayTime04 = ST14ChuoWei02Cy.cylinderPCToPLC_Global.tBackTime;
            CylinderDelay.DelayTime05 = ST14CarryJiaZhuaCy.cylinderPCToPLC_Global.tBackTime;
            CylinderDelay.DelayTime06 = ST14CarryUpDown01Cy.cylinderPCToPLC_Global.tGoTime;
            CylinderDelay.DelayTime07 = ST14CarryUpDown02Cy.cylinderPCToPLC_Global.tGoTime;
            CylinderDelay.DelayTime08 = ST14ChuoWei01Cy.cylinderPCToPLC_Global.tGoTime;
            CylinderDelay.DelayTime09 = ST14ChuoWei02Cy.cylinderPCToPLC_Global.tGoTime;
            CylinderDelay.DelayTime10 = ST14CarryJiaZhuaCy.cylinderPCToPLC_Global.tGoTime;

            IsCheck01 = InductorParam_Global.aByPass[16];
            IsCheck02 = InductorParam_Global.aByPass[17];
            IsCheck03 = InductorParam_Global.aByPass[18];
            CylinderDelay.DelayTime11 = InductorParam_Global.aDelay[16];
            CylinderDelay.DelayTime12 = InductorParam_Global.aDelay[17];
            CylinderDelay.DelayTime13 = InductorParam_Global.aDelay[18];


            checkModel.IsQGOriginCheck01 = ST14CarryUpDown01Cy.cylinderPCToPLC_Global.bOrgSenByPass;
            checkModel.IsQGOriginCheck02 = ST14CarryUpDown02Cy.cylinderPCToPLC_Global.bOrgSenByPass;
            checkModel.IsQGOriginCheck03 = ST14ChuoWei01Cy.cylinderPCToPLC_Global.bOrgSenByPass;
            checkModel.IsQGOriginCheck04 = ST14ChuoWei02Cy.cylinderPCToPLC_Global.bOrgSenByPass;
            checkModel.IsQGOriginCheck05 = ST14CarryJiaZhuaCy.cylinderPCToPLC_Global.bOrgSenByPass;


            checkModel.IsQGWorkCheck01 = ST14CarryUpDown01Cy.cylinderPCToPLC_Global.bWorkSenByPass;
            checkModel.IsQGWorkCheck02 = ST14CarryUpDown02Cy.cylinderPCToPLC_Global.bWorkSenByPass;
            checkModel.IsQGWorkCheck03 = ST14ChuoWei01Cy.cylinderPCToPLC_Global.bWorkSenByPass;
            checkModel.IsQGWorkCheck04 = ST14ChuoWei02Cy.cylinderPCToPLC_Global.bWorkSenByPass;
            checkModel.IsQGWorkCheck05 = ST14CarryJiaZhuaCy.cylinderPCToPLC_Global.bWorkSenByPass;

        }
        #region 事件


        private DelegateCommand _GoBackCommand;

        public DelegateCommand GoBackCommand =>
            _GoBackCommand ?? (_GoBackCommand = new DelegateCommand(ExecuteGoBackCommand));

        void ExecuteGoBackCommand()
        {
            NavigationParameters param = new NavigationParameters();
            param.Add("StationName", "ST14");
            _regionManager.RequestNavigate(PrismManager.MainViewRegionName, AppViews.ST14View, param);
        }

        /// <summary>
        /// 气缸感应器屏蔽
        /// </summary>
        private DelegateCommand<string> _CylinderPinBiCommand;
        public DelegateCommand<string> CylinderPinBiCommand =>
            _CylinderPinBiCommand ?? (_CylinderPinBiCommand = new DelegateCommand<string>(ExecuteCylinderPinBiCommand));

        void ExecuteCylinderPinBiCommand(string p)
        {
            switch (p)
            {
                case "ST14成品搬运1上下气缸原点":
                    ST14CarryUpDown01Cy.cylinderPCToPLC_Global.bOrgSenByPass = true;
                    break;
                case "ST14成品搬运2上下气缸原点":
                    ST14CarryUpDown02Cy.cylinderPCToPLC_Global.bOrgSenByPass = true;
                    break;
                case "ST14成品错位1气缸原点":
                    ST14ChuoWei01Cy.cylinderPCToPLC_Global.bOrgSenByPass = true;
                    break;
                case "ST14成品错位2气缸原点":
                    ST14ChuoWei02Cy.cylinderPCToPLC_Global.bOrgSenByPass = true;
                    break;
                case "ST14搬运夹爪气缸原点":
                    ST14CarryJiaZhuaCy.cylinderPCToPLC_Global.bOrgSenByPass = true;
                    break;


                case "ST14成品搬运1上下气缸动点":
                    ST14CarryUpDown01Cy.cylinderPCToPLC_Global.bWorkSenByPass = true;
                    break;
                case "ST14成品搬运2上下气缸动点":
                    ST14CarryUpDown02Cy.cylinderPCToPLC_Global.bWorkSenByPass = true;
                    break;
                case "ST14成品错位1气缸动点":
                    ST14ChuoWei01Cy.cylinderPCToPLC_Global.bWorkSenByPass = true;
                    break;
                case "ST14成品错位2气缸动点":
                    ST14ChuoWei02Cy.cylinderPCToPLC_Global.bWorkSenByPass = true;
                    break;
                case "ST14搬运夹爪气缸动点":
                    ST14CarryJiaZhuaCy.cylinderPCToPLC_Global.bWorkSenByPass = true;
                    break;
                case "ST14NG料盒检测":
                    InductorParam_Global.aByPass[16] = true;
                    break;
                case "ST14放料有无检测":
                    InductorParam_Global.aByPass[17] = true;
                    break;
                case "ST14振动盘满料检测":
                    InductorParam_Global.aByPass[18] = true;
                    break;

                case "ST14直振1启停":
                    VibratingPCToPLC_Global.Vibratings[5] = true;
                    break;
                case "ST14直振2启停":
                    VibratingPCToPLC_Global.Vibratings[6] = true;
                    break;
                default:
                    break;
            }
        }

        /// <summary>
        /// 气缸感应器解除屏蔽
        /// </summary>
        private DelegateCommand<string> _CylinderUnPinBiCommand;
        public DelegateCommand<string> CylinderUnPinBiCommand =>
            _CylinderUnPinBiCommand ?? (_CylinderUnPinBiCommand = new DelegateCommand<string>(ExecuteCylinderUnPinBiCommand));

        void ExecuteCylinderUnPinBiCommand(string p)
        {
            switch (p)
            {
                case "ST14成品搬运1上下气缸原点":
                    ST14CarryUpDown01Cy.cylinderPCToPLC_Global.bOrgSenByPass = false;
                    break;
                case "ST14成品搬运2上下气缸原点":
                    ST14CarryUpDown02Cy.cylinderPCToPLC_Global.bOrgSenByPass = false;
                    break;
                case "ST14成品错位1气缸原点":
                    ST14ChuoWei01Cy.cylinderPCToPLC_Global.bOrgSenByPass = false;
                    break;
                case "ST14成品错位2气缸原点":
                    ST14ChuoWei02Cy.cylinderPCToPLC_Global.bOrgSenByPass = false;
                    break;
                case "ST14搬运夹爪气缸原点":
                    ST14CarryJiaZhuaCy.cylinderPCToPLC_Global.bOrgSenByPass = false;
                    break;


                case "ST14成品搬运1上下气缸动点":
                    ST14CarryUpDown01Cy.cylinderPCToPLC_Global.bWorkSenByPass = false;
                    break;
                case "ST14成品搬运2上下气缸动点":
                    ST14CarryUpDown02Cy.cylinderPCToPLC_Global.bWorkSenByPass = false;
                    break;
                case "ST14成品错位1气缸动点":
                    ST14ChuoWei01Cy.cylinderPCToPLC_Global.bWorkSenByPass = false;
                    break;
                case "ST14成品错位2气缸动点":
                    ST14ChuoWei02Cy.cylinderPCToPLC_Global.bWorkSenByPass = false;
                    break;
                case "ST14搬运夹爪气缸动点":
                    ST14CarryJiaZhuaCy.cylinderPCToPLC_Global.bWorkSenByPass = false;
                    break;

                case "ST14NG料盒检测":
                    InductorParam_Global.aByPass[16] = false;
                    break;
                case "ST14放料有无检测":
                    InductorParam_Global.aByPass[17] = false;
                    break;
                case "ST14振动盘满料检测":
                    InductorParam_Global.aByPass[18] = false;
                    break;

                case "ST14直振1启停":
                    VibratingPCToPLC_Global.Vibratings[5] = false;
                    break;
                case "ST14直振2启停":
                    VibratingPCToPLC_Global.Vibratings[6] = false;
                    break;
                default:
                    break;
            }
        }

        private DelegateCommand<string> _TextChangeCommand;
        public DelegateCommand<string> TextChangeCommand =>
            _TextChangeCommand ?? (_TextChangeCommand = new DelegateCommand<string>(ExecuteTextChangeCommand));

        void ExecuteTextChangeCommand(string p)
        {
            switch (p)
            {

                case "DelayTime01":
                    ST14CarryUpDown01Cy.cylinderPCToPLC_Global.tBackTime = CylinderDelay.DelayTime01;
                    break;
                case "DelayTime02":
                    ST14CarryUpDown02Cy.cylinderPCToPLC_Global.tBackTime = CylinderDelay.DelayTime02;
                    break;
                case "DelayTime03":
                    ST14ChuoWei01Cy.cylinderPCToPLC_Global.tBackTime = CylinderDelay.DelayTime03;

                    break;

                case "DelayTime04":
                    ST14ChuoWei02Cy.cylinderPCToPLC_Global.tBackTime = CylinderDelay.DelayTime04;

                    break;
                case "DelayTime05":
                    ST14CarryJiaZhuaCy.cylinderPCToPLC_Global.tBackTime = CylinderDelay.DelayTime05;

                    break;
                case "DelayTime06":
                    ST14CarryUpDown01Cy.cylinderPCToPLC_Global.tGoTime = CylinderDelay.DelayTime06;

                    break;
                case "DelayTime07":
                    ST14CarryUpDown02Cy.cylinderPCToPLC_Global.tGoTime = CylinderDelay.DelayTime07;

                    break;
                case "DelayTime08":
                    ST14ChuoWei01Cy.cylinderPCToPLC_Global.tGoTime = CylinderDelay.DelayTime08;

                    break;
                case "DelayTime09":
                    ST14ChuoWei02Cy.cylinderPCToPLC_Global.tGoTime = CylinderDelay.DelayTime09;
                    break;
                case "DelayTime10":
                    ST14CarryJiaZhuaCy.cylinderPCToPLC_Global.tGoTime = CylinderDelay.DelayTime10;
                    break;
                case "DelayTime11":
                    InductorParam_Global.aDelay[16] = CylinderDelay.DelayTime11;
                    break;
                case "DelayTime12":
                    InductorParam_Global.aDelay[17] = CylinderDelay.DelayTime12;
                    break;
                case "DelayTime13":
                    InductorParam_Global.aDelay[18] = CylinderDelay.DelayTime13;
                    break;
                default:
                    break;
            }
        }

        #endregion


        #region 属性  

        private CylinderDelayModel _cylinderDelay;
        public CylinderDelayModel CylinderDelay
        {
            get { return _cylinderDelay ?? (_cylinderDelay = new CylinderDelayModel()); }
            set { SetProperty(ref _cylinderDelay, value); }
        }


        private bool _IsCheck01;
        public bool IsCheck01
        {
            get { return _IsCheck01; }
            set { SetProperty(ref _IsCheck01, value); }
        }


        private bool _IsCheck02;
        public bool IsCheck02
        {
            get { return _IsCheck02; }
            set { SetProperty(ref _IsCheck02, value); }
        }

        private bool _IsCheck03;
        public bool IsCheck03
        {
            get { return _IsCheck03; }
            set { SetProperty(ref _IsCheck03, value); }
        }

        private bool _IsCheck04;
        public bool IsCheck04
        {
            get { return _IsCheck04; }
            set { SetProperty(ref _IsCheck04, value); }
        }

        private bool _IsCheck05;
        public bool IsCheck05
        {
            get { return _IsCheck05; }
            set { SetProperty(ref _IsCheck05, value); }
        }


        private bool _IsCheck06;
        public bool IsCheck06
        {
            get { return _IsCheck06; }
            set { SetProperty(ref _IsCheck06, value); }
        }

        private bool _IsCheck07;
        public bool IsCheck07
        {
            get { return _IsCheck07; }
            set { SetProperty(ref _IsCheck07, value); }
        }
        private CylinderSensorCheckModel _checkModel;
        public CylinderSensorCheckModel checkModel
        {
            get { return _checkModel ?? (_checkModel = new CylinderSensorCheckModel()); }
            set { SetProperty(ref _checkModel, value); }
        }
        #endregion
    }
}
